package 字节码文件.异常处理指令;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 异常处理指令
 * <P> Date: 2022/3/27:20:38
 * <P> Description:
 */

public class ExceptionTest {

    public void throwZero(int i) {
        if (i == 0) {
            throw new RuntimeException("参数值为0");
        }
    }

    //throws抛出 方法会有属性 叫做Exceptions
    public void throwOne(int i) throws RuntimeException {
        if (i == 1) {
            throw new RuntimeException("参数值为1");
        }
    }

    //不会在字节码中显示 由虚拟机抛出
    public void throwArithmetic() {
        int i = 10;
        int j = i / 0;
        System.out.println(j);
    }

    public void tryCatch() {
        try {
            File file = new File("d:/test");
            FileInputStream fis = new FileInputStream(file);

            String info = "hello";
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    public static String func() {
        String str = "hello";
        try {
            return str;

        } finally {
            str = "atiguigu";
        }
    }

    public static void main(String[] args) {
        System.out.println(func());
    }
}
